<?php
include_once('../../php/postgre.php');

$act =' ';
if(isset($_POST['act']))
	$act = $_POST['act'];
	
if($act=='tmpl_laporan'){
	echo 'ok___';
	$cb = new laporan();
	$cb -> view_data();
}

class laporan{
	
	function view_data(){		
		$id_bidang = (isset($_POST['b']))?abs($_POST['b']):abs($_GET['b']);
		$tahun = (isset($_POST['t']))?abs($_POST['t']):abs($_GET['t']);
		$tahunAng = get_data("SELECT * FROM spm_thn_angg where id_thn_angg = $tahun");
		
		if(!empty($id_bidang)){
			$find_bidang = "and b.id_bidang = '$id_bidang' ";
		}
		
		if(!empty($tahun)){
			$find_tahun ="and t.thn_angg='$tahun'";
		}
		
		$no = 1;
		$pelayanan = get_datas("SELECT DISTINCT p.nama_pelayanan, p.id_pelayanan FROM spm_jenis_pelayanan p, spm_indikator i, spm_bidang_urusan b WHERE p.id_pelayanan = i.id_pelayanan and p.id_bidang = '$id_bidang' and p.id_thn_angg = '$tahun'");
		
		if(count($pelayanan) > 0){
			foreach ($pelayanan as $pelayanan){
				$idpelayanan = $pelayanan['id_pelayanan'];
				?>
				
				<tr>
					<td style="text-align:center;"><?php echo $no?></td>
					<td colspan="7"><?php echo $pelayanan['nama_pelayanan'] ?></td>
				</tr>
				<?php
				$nmr = 1;
				$indikator= get_datas("SELECT DISTINCT i.nama_indikator, i.nilai_spm, i.tahun_batas_capaian, c.tahun_capaian,c.nilai_capaian FROM spm_indikator i, spm_capaian_spm c, spm_jenis_pelayanan p WHERE c.tahun_capaian = '".$tahunAng['thn_angg']."' AND i.id_indikator = c.id_indikator AND i.id_pelayanan =" .$pelayanan['id_pelayanan'] );
				
				if(count($indikator) > 0){
					foreach($indikator as $indikator){
					
						$standart = $indikator['nilai_spm'];
						$capaian = $indikator['nilai_capaian'];
						$selisih = $standart - $capaian;
						?>
						<tr>
							<td>&nbsp; </td>
							<td style="text-align:center; width:30px;"><?php echo $no?></td>
							<td><?php echo $indikator['nama_indikator'] ?></td>
							<td><?php echo $indikator['nilai_spm'] ?></td>
							<td><?php echo $indikator['tahun_batas_capaian'] ?></td>
							<td><?php echo $indikator['nilai_capaian'] ?></td>
							<td><?php echo $selisih ?></td>
						</tr>
						<?php
						$nmr++;
					}
				}
			$no++;
			}
			
		}
		
	}
}

?>